package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.TableTypeService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.TableTypeAddVO;
import com.junzhiit.nengji.cms.web.vo.TableTypeEditVO;
import com.junzhiit.nengji.cms.web.vo.TableTypeVO;

@RestController
@RequestMapping("/table/type")
public class TableTypeController extends BaseController{
	
	@Autowired
	private TableTypeService tableTypeService;
	
	@RequestMapping(method=RequestMethod.GET)
	public Map<String, Object> findPageAll(DataTablesParamVO dtp,TableTypeVO tableTypeVO){
		return tableTypeService.findPageAll(dtp,tableTypeVO);
	}
	
	@RequestMapping(value="/all",method=RequestMethod.GET)
	public ResultVO getAll(TableTypeVO tableTypeVO){
		return tableTypeService.getAll(tableTypeVO);
	}
	
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public ResultVO findById(@PathVariable String id){
		return tableTypeService.findById(id);
	}
	
	@RequestMapping(method=RequestMethod.POST)
	public ResultVO add(TableTypeAddVO tableTypeAddVO){
		AssertUtil.notBlank(tableTypeAddVO.getName(), "name is required");
		AssertUtil.notNull(tableTypeAddVO.getBasicMoney(), "basicMoney is required");
		AssertUtil.notNull(tableTypeAddVO.getIncrementPeople(), "incrementPeople is required");
		AssertUtil.notNull(tableTypeAddVO.getIncrementMoney(), "incrementMoney is required");
		
		return tableTypeService.add(tableTypeAddVO);
	}
	
	@RequestMapping(value="/{id}",method=RequestMethod.PUT)
	public ResultVO edit(@PathVariable String id,TableTypeEditVO tableTypeEditVO){
		AssertUtil.notBlank(id, "id is required");
		AssertUtil.notBlank(tableTypeEditVO.getName(), "name is required");
		AssertUtil.notNull(tableTypeEditVO.getBasicMoney(), "basicMoney is required");
		AssertUtil.notNull(tableTypeEditVO.getIncrementPeople(), "incrementPeople is required");
		AssertUtil.notNull(tableTypeEditVO.getIncrementMoney(), "incrementMoney is required");
		return tableTypeService.edit(id, tableTypeEditVO);
	}
	
	@RequestMapping(value="/delete/{id}",method=RequestMethod.PUT)
	public ResultVO updateToDelete(@PathVariable String id){
		AssertUtil.notBlank(id, "id is required");
		return tableTypeService.updateToDelete(id);
	}
	
}
